home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / dino / dino_bot.1 / examples / smoothing / ex2.d < prev    next >
Encoding:
Text File  |  1991-03-10  |  2.8 KB  |  100 lines

  1. /* Copyright, 1990, Regents of the University of Colorado */
  2. /* This program performs a vertical smoothing, with the matrix partitioned
  3.  * by columns, with multiple columns per processor.  The matrix is of size
  4.  * M x N, where N must be a multiple of P. */
  5.  
  6. #include "dino.h"
  7.  
  8. #define max(x,y) (x > y ? x : y)
  9. #define min(x,y) (x < y ? x : y)
  10.  
  11. #define M 16
  12. #define N 16
  13. #define P 4
  14.  
  15. environment node[P:id] {
  16.  
  17.   composite smooth (a, in iter)
  18.   double distributed a[M][N] map BlockColOverlap;
  19.   int iter;
  20.  
  21.   {
  22.     int i, j, k;                /* Looping variables */
  23.  
  24.     /* Repeat the smoothing process iter times */
  25.     for (i = 0; i < iter; i++) {
  26.  
  27.       /* Send out your data and receive it back again, if not the first
  28.        * iteration */
  29.       if (i != 0) {
  30.  
  31.         a[][<id * N/P,(id + 1) * N/P - 1>]# =
  32.         a[][<id * N/P,(id + 1) * N/P - 1>];
  33.  
  34.                                 /* ==> This statement sends out those columns
  35.                                        of a which are "home" on this
  36.                                        environment.  Only those columns which
  37.                                        have copies on another environment
  38.                                        are actually sent. */
  39.  
  40.         a[][<max(id * N/P - 1, 0),min((id + 1) * N/P, N - 1)>]#;
  41.  
  42.                                 /* ==> Receives the "copy" rows.  Only those
  43.                                        columns which are copies are actually
  44.                                        sent.  The max() and min() calls
  45.                                        deal with the edge cases */
  46.  
  47.       }
  48.  
  49.       /* Perform the computation, but only on non-edge columns */
  50.       for (j = 0; j < M; j++)
  51.         for (k = max(id * N/P, 1); k <= min((id + 1) * N/P - 1, N - 2); k++)
  52.           a[j][k] = (a[j][k-1] + a[j][k+1]) / 2;
  53.  
  54.     }
  55.   }
  56. }
  57.  
  58. environment host {
  59.  
  60.   void main ()
  61.  
  62.   {
  63.     double a[M][N];                     /* Input data */
  64.     int iter;                           /* Holds the iteration count */
  65.  
  66.     int i, j;                           /* Looping variables */
  67.  
  68.     /* Set up the initial data for a[][] */
  69.     for (i = 0; i < M; i++)
  70.       for (j = 0; j < N; j++)
  71.         a[i][j] = (i + 1)*(j + 1);
  72.     for (i = 0; i < M; i++)
  73.       for (j = 1; j < N - 1; j++)
  74.         a[i][j] = 0;
  75.  
  76.     /* Set up the variable which will contain the number of iterations */
  77.     iter = 300;
  78.  
  79.     /* Print out the initial data */
  80.     printf ("Initial data for a:\n");
  81.     for (i = 0; i < M; i++) {
  82.       for (j = 0; j < N; j++)
  83.         printf ("%6.2f", a[i][j]);
  84.       printf ("\n");
  85.     }
  86.  
  87.     /* Perform the computation */
  88.     smooth (a[][], iter)#;
  89.  
  90.     /* Printout the results */
  91.     printf ("Result data for a:\n");
  92.     for (i = 0; i < M; i++) {
  93.       for (j = 0; j < N; j++)
  94.         printf ("%6.2f", a[i][j]);
  95.       printf ("\n");
  96.     }
  97.   }
  98. }
  99.  
  100.